
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>mongodb驱动与连接 · tgor note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tgor">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../Mongodb/mongodb-ObjectId实践.html" />
    
    
    <link rel="prev" href="morphia-API汇总.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../category/微服务.html">
            
                <a href="../category/微服务.html">
            
                    
                    微服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Java-Spring/Feign.html">
            
                <a href="../Java-Spring/Feign.html">
            
                    
                    HTTP客户端Feign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Java-其他库/限流.html">
            
                <a href="../Java-其他库/限流.html">
            
                    
                    限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    限流Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../Java-Spring/负载均衡.html">
            
                <a href="../Java-Spring/负载均衡.html">
            
                    
                    负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    负载均衡Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../Java-其他库/熔断Hystrix.html">
            
                <a href="../Java-其他库/熔断Hystrix.html">
            
                    
                    熔断Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html#本地缓存">
            
                    
                    本地缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    分布式缓存Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html">
            
                    
                    分布式事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html#事务消息">
            
                    
                    可靠事务消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../Java-Spring/业务监控.html">
            
                <a href="../Java-Spring/业务监控.html">
            
                    
                    业务监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="../Java-其他库/分布式定时作业.html">
            
                <a href="../Java-其他库/分布式定时作业.html">
            
                    
                    分布式作业调度ElasticJob
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../Java-ORM/ORM.html">
            
                <a href="../Java-ORM/ORM.html">
            
                    
                    ORM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="../Java-其他库/分布式系统及CAP原理.html">
            
                <a href="../Java-其他库/分布式系统及CAP原理.html">
            
                    
                    分布式系统及CAP原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" data-path="../MQ/RabbitMQ笔记.html">
            
                <a href="../MQ/RabbitMQ笔记.html">
            
                    
                    消息驱动Rabbitmq
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../category/数据库.html">
            
                <a href="../category/数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Mysql/经典数据库设计案例.html">
            
                <a href="../Mysql/经典数据库设计案例.html">
            
                    
                    mysql设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Mysql/Mysql事务与锁.html">
            
                <a href="../Mysql/Mysql事务与锁.html">
            
                    
                    mysql事务与锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../Mysql/mysql数据类型.html">
            
                <a href="../Mysql/mysql数据类型.html">
            
                    
                    mysql数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html">
            
                    
                    mysql索引与查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html#查询语句设计准则">
            
                    
                    mysql查询语句设计准则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../Mysql/mysql性能测试.html">
            
                <a href="../Mysql/mysql性能测试.html">
            
                    
                    mysql性能测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../Mysql/mysql主从同步与读写分离.html">
            
                <a href="../Mysql/mysql主从同步与读写分离.html">
            
                    
                    mysql主从同步与读写分离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                    
                    Spring事务注解@Transactional
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../数据结构与算法/位运算应用实例.html">
            
                <a href="../数据结构与算法/位运算应用实例.html">
            
                    
                    位运算应用实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="morphia-API汇总.html">
            
                <a href="morphia-API汇总.html">
            
                    
                    morphia API汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.11" data-path="mongo驱动连接.html">
            
                <a href="mongo驱动连接.html">
            
                    
                    mongodb驱动与连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../Mongodb/mongodb-ObjectId实践.html">
            
                <a href="../Mongodb/mongodb-ObjectId实践.html">
            
                    
                    mongodb ObjectId实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../Mongodb/mongodb角色权限.html">
            
                <a href="../Mongodb/mongodb角色权限.html">
            
                    
                    mongodb角色权限
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../category/java并发.html">
            
                <a href="../category/java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#锁">
            
                    
                    Java并发之锁设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#synchronized">
            
                    
                    Java并发之synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantlock">
            
                    
                    Java Lock之ReentrantLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantreadwritelock">
            
                    
                    Java Lock之ReentrantReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html">
            
                    
                    Java Future
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#futuretask">
            
                    
                    Java Future之FutureTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#completablefuture">
            
                    
                    Java Future之CompletableFuture
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#forkjointask">
            
                    
                    Java Future之ForkJoinTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../Java-Base/Java之Thread.html">
            
                <a href="../Java-Base/Java之Thread.html">
            
                    
                    Java Thread
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../category/redis.html">
            
                <a href="../category/redis.html">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#集群">
            
                    
                    Redis集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#消息订阅">
            
                    
                    Redis消息订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#lua">
            
                    
                    Redis Lua脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#配置汇总">
            
                    
                    Redis配置汇总
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../category/运维.html">
            
                <a href="../category/运维.html">
            
                    
                    运维
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../运维/Linux常用操作汇总.html">
            
                <a href="../运维/Linux常用操作汇总.html">
            
                    
                    Linux常用操作汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../运维/阿里云笔记.html">
            
                <a href="../运维/阿里云笔记.html">
            
                    
                    阿里云笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../category/nginx.html">
            
                <a href="../category/nginx.html">
            
                    
                    Nginx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html">
            
                    
                    Nginx基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    Nginx负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    Nginx限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html#六、其他">
            
                    
                    Nginx客户端辅助技巧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../category/容器化.html">
            
                <a href="../category/容器化.html">
            
                    
                    容器化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html">
            
                    
                    Docker学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#基础操作">
            
                    
                    Docker基础操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#dockerfile">
            
                    
                    DockerFile
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../category/Web.html">
            
                <a href="../category/Web.html">
            
                    
                    Web
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../运维/Http入坑Https笔记.html">
            
                <a href="../运维/Http入坑Https笔记.html">
            
                    
                    Http入坑Https笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Web/阿里云OSS.html">
            
                <a href="../Web/阿里云OSS.html">
            
                    
                    OSS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../category/java基础.html">
            
                <a href="../category/java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#jvm">
            
                    
                    JVM基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#语法糖">
            
                    
                    Java语法糖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#数据结构">
            
                    
                    Java数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../Java-Base/Java8函数式编程.html">
            
                <a href="../Java-Base/Java8函数式编程.html">
            
                    
                    java8函数式编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../Java-Base/ArrayList源码分析.html">
            
                <a href="../Java-Base/ArrayList源码分析.html">
            
                    
                    JDK源码分析ArrayList
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../Java-Base/HashMap源码分析.html">
            
                <a href="../Java-Base/HashMap源码分析.html">
            
                    
                    JDK源码分析HashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../Java-Base/Java注解.html">
            
                <a href="../Java-Base/Java注解.html">
            
                    
                    Java注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../Java-Base/Timsort排序算法.html">
            
                <a href="../Java-Base/Timsort排序算法.html">
            
                    
                    Timsort排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../Java-Base/插入排序分析与Java实现.html">
            
                <a href="../Java-Base/插入排序分析与Java实现.html">
            
                    
                    插入排序分析与Java实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../category/工具与规范.html">
            
                <a href="../category/工具与规范.html">
            
                    
                    工具与规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../工具/Maven使用技巧汇总.html">
            
                <a href="../工具/Maven使用技巧汇总.html">
            
                    
                    Maven使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../编码规范/Java编码规范.html">
            
                <a href="../编码规范/Java编码规范.html">
            
                    
                    Java编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../category/OLAP.html">
            
                <a href="../category/OLAP.html">
            
                    
                    OLAP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../数据处理/storm学习笔记.html">
            
                <a href="../数据处理/storm学习笔记.html">
            
                    
                    流式计算Storm学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../category/数据运营.html">
            
                <a href="../category/数据运营.html">
            
                    
                    数据运营
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../数据运营/增长黑客数据运营.html">
            
                <a href="../数据运营/增长黑客数据运营.html">
            
                    
                    增长黑客-数据运营
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../category/前端技术栈.html">
            
                <a href="../category/前端技术栈.html">
            
                    
                    前端技术栈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../前端/JavaScript设计模式.html">
            
                <a href="../前端/JavaScript设计模式.html">
            
                    
                    JavaScript设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../前端/html相对路径与绝对路径.html">
            
                <a href="../前端/html相对路径与绝对路径.html">
            
                    
                    Html相对路径与绝对路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../前端/微信小程序学习笔记.html">
            
                <a href="../前端/微信小程序学习笔记.html">
            
                    
                    微信小程序学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../category/个人.html">
            
                <a href="../category/个人.html">
            
                    
                    个人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../个人/简历.html">
            
                <a href="../个人/简历.html">
            
                    
                    简历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >mongodb驱动与连接</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="mongo&#x9A71;&#x52A8;&#x8FDE;&#x63A5;">mongo&#x9A71;&#x52A8;&#x8FDE;&#x63A5;</h1>
<p>&#x6807;&#x7B7E;&#xFF08;&#x7A7A;&#x683C;&#x5206;&#x9694;&#xFF09;&#xFF1A; Mongodb-Client Mongodb</p>
<hr>
<p>&#x5B98;&#x65B9;&#x6587;&#x6863;&#xFF1A;<a href="https://docs.mongodb.com/manual/reference/connection-string/" target="_blank">Connection String URI Format</a></p>
<p>DBA&#x7279;&#x522B;&#x63A8;&#x8350;&#xFF1A;<a href="http://www.mongoing.com/archives/3909" target="_blank">MongoDB Driver&#xFF1A;&#x4F7F;&#x7528;&#x6B63;&#x786E;&#x7684;&#x59FF;&#x52BF;&#x8FDE;&#x63A5;&#x5206;&#x7247;&#x96C6;&#x7FA4;</a></p>
<p>&#x5176;&#x4E2D;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF1A;mongos&#x94FE;&#x63A5;&#xFF0C;&#x63A8;&#x8350;&#x914D;&#x7F6E;&#x591A;&#x53F0;mongos&#x5B9E;&#x73B0;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#xFF0C;&#x56E0;&#x6B64;&#x5728;&#x914D;&#x7F6E;&#x5206;&#x7247;&#x96C6;&#x7FA4;&#x65F6;&#xFF0C;&#x9A71;&#x52A8;&#x94FE;&#x63A5;&#x540C;&#x6837;&#x5E94;&#x8BE5;
&#x914D;&#x7F6E;&#x591A;&#x4E2A;<code>mongos</code>&#x5730;&#x5740;</p>
<ul>
<li>&#x7528;&#x6237;&#x8BBF;&#x95EE; mongos &#x8DDF;&#x8BBF;&#x95EE;&#x5355;&#x4E2A; mongod &#x7C7B;&#x4F3C;</li>
<li>&#x6240;&#x6709; mongos &#x662F;&#x5BF9;&#x7B49;&#x5173;&#x7CFB;&#xFF0C;&#x7528;&#x6237;&#x8BBF;&#x95EE;&#x5206;&#x7247;&#x96C6;&#x7FA4;&#x53EF;&#x901A;&#x8FC7;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;mongos</li>
<li>mongos &#x672C;&#x8EAB;&#x662F;&#x65E0;&#x72B6;&#x6001;&#x7684;&#xFF0C;&#x53EF;&#x4EFB;&#x610F;&#x6269;&#x5C55;&#xFF0C;&#x96C6;&#x7FA4;&#x7684;&#x670D;&#x52A1;&#x80FD;&#x529B;&#x4E3A;&#x300E;Shard&#x670D;&#x52A1;&#x80FD;&#x529B;&#x4E4B;&#x548C;&#x300F;&#x4E0E;&#x300E;mongos&#x670D;&#x52A1;&#x80FD;&#x529B;&#x4E4B;&#x548C;&#x300F;&#x7684;&#x6700;&#x5C0F;&#x503C;&#x3002;</li>
<li>&#x8BBF;&#x95EE;&#x5206;&#x7247;&#x96C6;&#x7FA4;&#x65F6;&#xFF0C;&#x6700;&#x597D;&#x5C06;&#x5E94;&#x7528;&#x8D1F;&#x8F7D;&#x5747;&#x5300;&#x7684;&#x5206;&#x6563;&#x5230;&#x591A;&#x4E2A; mongos &#x4E0A;</li>
</ul>
<p><strong>&#x9A71;&#x52A8;&#x94FE;&#x63A5;&#x683C;&#x5F0F;</strong>&#xFF1A;<code>mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]</code></p>
<h3 id="&#x57FA;&#x7840;&#x9009;&#x9879;">&#x57FA;&#x7840;&#x9009;&#x9879;</h3>
<table>
<thead>
<tr>
<th>&#x57FA;&#x7840;&#x9009;&#x9879;</th>
<th>&#x8BF4;&#x660E;</th>
<th>&#x793A;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>mongodb://</td>
<td>&#x5FC5;&#x5199;&#x524D;&#x7F00;</td>
<td></td>
</tr>
<tr>
<td>host1</td>
<td><strong>&#x5355;&#x70B9;mongod</strong>&#xFF1A;&#x6307;&#x5B9A;&#x5355;&#x70B9;&#x670D;&#x52A1;&#x5730;&#x5740;&#xFF1B;<strong>&#x526F;&#x672C;&#x96C6;</strong>&#xFF1A;&#x4EE5;<code>,</code>&#x5206;&#x9694;&#xFF0C;&#x914D;&#x7F6E;&#x526F;&#x672C;&#x96C6;&#x6240;&#x6709;&#x670D;&#x52A1;&#x5730;&#x5740;&#xFF1B;&#x5206;&#x7247;&#x96C6;&#x7FA4;&#xFF1A;&#x4EE5;<code>,</code>&#x5206;&#x9694;&#xFF0C;&#x914D;&#x7F6E;&#x526F;&#x672C;&#x96C6;&#x6240;&#x6709;<strong>mongos</strong>&#x670D;&#x52A1;&#x5730;&#x5740;&#xFF1B;&#x53C2;&#x7167;&#x4EE5;&#x4E0B;&#x793A;&#x4F8B;</td>
<td></td>
</tr>
<tr>
<td>:port1</td>
<td>&#x7AEF;&#x53E3;&#xFF0C;&#x9ED8;&#x8BA4;27017</td>
<td></td>
</tr>
<tr>
<td>/database</td>
<td>&#x9274;&#x6743;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;admin&#xFF1B;&#x5EFA;&#x8BAE;&#x5FC5;&#x586B;</td>
<td></td>
</tr>
<tr>
<td>/database</td>
<td>&#x9274;&#x6743;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;admin&#xFF1B;&#x5EFA;&#x8BAE;&#x5FC5;&#x586B;</td>
</tr>
</tbody>
</table>
<p>&#x793A;&#x4F8B;&#xFF1A;<code>mongodb://tgor:12345678@192.168.101.41:27017,192.168.101.42:27017,192.168.101.43:27017/db1</code></p>
<h3 id="&#x526F;&#x672C;&#x96C6;&#x9009;&#x9879;">&#x526F;&#x672C;&#x96C6;&#x9009;&#x9879;</h3>
<table>
<thead>
<tr>
<th>&#x526F;&#x672C;&#x96C6;&#x9009;&#x9879;</th>
<th>&#x8BF4;&#x660E;</th>
<th>&#x793A;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>replicaSet</td>
<td>&#x526F;&#x672C;&#x96C6;&#x540D;&#x79F0;&#xFF0C;&#x9700;&#x8981;&#x914D;&#x7F6E;&#x591A;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#x8282;&#x70B9;&#x4F7F;&#x7528;&#xFF0C;&#x5982;&#x679C;&#x53EA;&#x914D;&#x7F6E;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#xFF0C;&#x9A71;&#x52A8;&#x53EA;&#x4F1A;&#x94FE;&#x63A5;&#x5176;&#x4E00;</td>
</tr>
</tbody>
</table>
<p>&#x793A;&#x4F8B;&#xFF1A;<code>mongodb://tgor:12345678@192.168.101.41:27017,192.168.101.42:27017,192.168.101.43:27017/db1?replicaSet=testRS</code></p>
<h3 id="&#x8FDE;&#x63A5;&#x9009;&#x9879;">&#x8FDE;&#x63A5;&#x9009;&#x9879;</h3>
<table>
<thead>
<tr>
<th>&#x8FDE;&#x63A5;&#x9009;&#x9879;</th>
<th>&#x8BF4;&#x660E;</th>
<th>&#x793A;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>ssl</td>
<td><strong>true</strong>: &#x4F7F;&#x7528;TLS/SSL&#x521D;&#x59CB;&#x5316;&#x8FDE;&#x63A5;&#xFF1B;<strong>&#x9ED8;&#x8BA4;false</strong>: &#x4E0D;&#x4F7F;&#x7528;TLS/SSL&#x521D;&#x59CB;&#x5316;&#x8FDE;&#x63A5;</td>
<td></td>
</tr>
<tr>
<td>connectTimeoutMS</td>
<td>&#x94FE;&#x63A5;&#x8D85;&#x65F6;&#x6BEB;&#x79D2;&#x6570;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x6C38;&#x4E0D;&#x8D85;&#x65F6;&#xFF0C;&#x5EFA;&#x8BAE;&#x5FC5;&#x586B;</td>
<td></td>
</tr>
<tr>
<td>maxPoolSize</td>
<td>&#x8FDE;&#x63A5;&#x6C60;&#x8FDE;&#x63A5;&#x6570;&#x6700;&#x5927;&#x503C;&#xFF0C;&#x9ED8;&#x8BA4;100</td>
<td></td>
</tr>
<tr>
<td>minPoolSize</td>
<td>&#x8FDE;&#x63A5;&#x6C60;&#x8FDE;&#x63A5;&#x6570;&#x6700;&#x5C0F;&#x503C;&#xFF0C;&#x9ED8;&#x8BA4;0</td>
<td></td>
</tr>
<tr>
<td>waitQueueMultiple</td>
<td>&#x9A71;&#x52A8;&#x5F3A;&#x884C;&#x9650;&#x5236;&#x7EBF;&#x7A0B;&#x540C;&#x65F6;&#x7B49;&#x5F85;&#x8FDE;&#x63A5;&#x7684;&#x4E2A;&#x6570;</td>
<td></td>
</tr>
<tr>
<td>waitQueueTimeoutMS</td>
<td>&#x5728;&#x8D85;&#x65F6;&#x4E4B;&#x524D;&#xFF0C;&#x7EBF;&#x7A0B;&#x7B49;&#x5F85;&#x8FDE;&#x63A5;&#x751F;&#x6548;&#x7684;&#x603B;&#x65F6;&#x95F4;&#x3002;&#x5982;&#x679C;&#x8FDE;&#x63A5;&#x6C60;&#x5230;&#x8FBE;&#x6700;&#x5927;&#x5E76;&#x4E14;&#x6240;&#x6709;&#x7684;&#x8FDE;&#x63A5;&#x90FD;&#x5728;&#x4F7F;&#x7528;&#xFF0C;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x5C31;&#x751F;&#x6548;&#x4E86;</td>
</tr>
</tbody>
</table>
<h3 id="&#x3010;&#x5199;&#x3011;&#x9009;&#x9879;">&#x3010;&#x5199;&#x3011;&#x9009;&#x9879;</h3>
<table>
<thead>
<tr>
<th>&#x3010;&#x5199;&#x3011;&#x9009;&#x9879;</th>
<th>&#x8BF4;&#x660E;</th>
<th>&#x793A;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>w</td>
<td><strong>w = N &gt;= 1</strong>&#xFF1A;&#x8868;&#x793A;&#x5199;&#x64CD;&#x4F5C;&#xFF0C;&#x5F97;&#x5230;N&#x4E2A;&#x5B9E;&#x4F8B;&#x6216;N&#x4E2A;&#x526F;&#x672C;&#x96C6;&#x8282;&#x70B9;&#x786E;&#x8BA4;&#x5B89;&#x5168;&#x5199;&#x5165;&#xFF0C;v2.0&#x7248;&#x672C;&#x4EE5;&#x540E;&#x4E3A;&#x9ED8;&#x8BA4;&#x9009;&#x9879;&#xFF1B;<strong>0</strong>&#xFF1A;&#x975E;&#x5B89;&#x5168;&#x5199;&#x5165;&#xFF0C;&#x8868;&#x793A;&#x5199;&#x64CD;&#x4F5C;&#xFF0C;&#x65E0;&#x9700;&#x5F97;&#x5230;&#x5B9E;&#x4F8B;&#x786E;&#x8BA4;</td>
<td></td>
</tr>
<tr>
<td>wtimeoutMS</td>
<td>&#x5199;&#x64CD;&#x4F5C;&#x8D85;&#x65F6;&#x6BEB;&#x79D2;&#x6570;&#xFF0C;<strong>0</strong>&#xFF1A;&#x4E0D;&#x9650;&#x5236;</td>
<td></td>
</tr>
<tr>
<td>journal</td>
<td>&#x64CD;&#x4F5C;&#x65E5;&#x5FD7;&#x9009;&#x9879;&#xFF1A;<strong>true</strong>&#xFF1A;&#x6570;&#x636E;&#x5728;&#x5199;&#x5165;&#x5230;DB&#x78C1;&#x76D8;&#x6587;&#x4EF6;&#x4E4B;&#x524D;&#xFF0C;MongoDB&#x4F1A;&#x5148;&#x628A;&#x64CD;&#x4F5C;&#x5199;&#x5165;&#x5230;Journal&#x6587;&#x4EF6;&#xFF0C;&#x662F;&#x786E;&#x8BA4;&#x5199;&#x5165;&#x4E86;Journal&#x6587;&#x4EF6;&#x5C31;&#x8FD4;&#x56DE;&#xFF1B;<strong>false</strong>&#xFF1A;&#x53CD;&#x4E4B;&#xFF1B;&#x53C2;&#x8003;&#xFF1A;<a href="https://www.zybuluo.com/zero1036/note/708431" target="_blank">mongodb&#x8BFB;&#x5199;&#x6027;&#x80FD;&#x5206;&#x6790;</a></td>
</tr>
</tbody>
</table>
<p>&#x6CE8;&#x610F;&#xFF1A;&#xFF08;<a href="https://docs.mongodb.com/manual/reference/write-concern/#wc-j" target="_blank">&#x5B98;&#x6587;</a>&#xFF09;</p>
<ol>
<li>&#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E86;wtimeoutMS&#x5199;&#x64CD;&#x4F5C;&#x8D85;&#x65F6;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x8981;&#x8BBE;&#x7F6E;<code>w&gt;0</code>&#xFF0C;&#x9A71;&#x52A8;&#x8981;&#x6C42;&#x786E;&#x8BA4;&#x5B89;&#x5168;&#x5199;&#x5165;&#xFF1B;</li>
<li><code>w</code>&#x4E0E;<code>j</code>&#x51B3;&#x5B9A;&#x4E86;&#x670D;&#x52A1;&#x7AEF;&#x4F55;&#x65F6;&#x786E;&#x8BA4;&#x5199;&#x64CD;&#x4F5C;&#x6210;&#x529F;&#xFF1A;The w option and the j option determine when mongod instances acknowledge write operations.&#xFF08;&#x53C2;&#x8003;&#x4E0B;&#x8868;&#xFF09;</li>
</ol>
<table>
<thead>
<tr>
<th>-</th>
<th>j:&#x672A;&#x6307;&#x5B9A;</th>
<th>j:true</th>
<th>j:false</th>
</tr>
</thead>
<tbody>
<tr>
<td>w:1</td>
<td>In memory&#xFF1A;&#x5199;&#x5165;&#x5185;&#x5B58;&#x5373;&#x786E;&#x8BA4;</td>
<td>On-disk journal&#xFF1A;&#x5199;&#x5165;&#x78C1;&#x76D8;&#x65E5;&#x5FD7;</td>
<td>In memory&#xFF1A;&#x5199;&#x5165;&#x5185;&#x5B58;&#x5373;&#x786E;&#x8BA4;</td>
</tr>
<tr>
<td>w:&quot;majority&quot;</td>
<td>On-disk journal if running with journaling</td>
<td>On-disk journal</td>
<td>In memory</td>
</tr>
</tbody>
</table>
<h3 id="&#x670D;&#x52A1;&#x9009;&#x62E9;&#x4E0E;&#x53D1;&#x73B0;&#x9009;&#x9879;">&#x670D;&#x52A1;&#x9009;&#x62E9;&#x4E0E;&#x53D1;&#x73B0;&#x9009;&#x9879;</h3>
<table>
<thead>
<tr>
<th>&#x5176;&#x4ED6;&#x9009;&#x9879;</th>
<th>&#x8BF4;&#x660E;</th>
<th>&#x793A;&#x4F8B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>heartbeatFrequencyMS</td>
<td>&#x5FC3;&#x8DF3;&#x95F4;&#x9699;&#x957F;&#x5EA6;&#xFF08;&#x6BEB;&#x79D2;&#xFF09;</td>
</tr>
</tbody>
</table>
<h2 id="java&#x9A71;&#x52A8;&#x793A;&#x4F8B;">Java&#x9A71;&#x52A8;&#x793A;&#x4F8B;</h2>
<p>&#x6CE8;&#x610F;&#xFF1A;MongoClient&#x4F1A;&#x81EA;&#x52A8;&#x521B;&#x5EFA;&#x8FDE;&#x63A5;&#x6C60;&#xFF0C;&#x56E0;&#x6B64;&#xFF0C;&#x5927;&#x90E8;&#x5206;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6574;&#x4E2A;JVM&#x5E94;&#x7528;&#x4E2D;&#x53EA;&#x9700;&#x8981;&#x6709;&#x4E00;&#x4E2A;MongoClient&#x5B9E;&#x4F8B;&#x5C31;&#x53EF;&#x4EE5;&#x3002;</p>
<pre><code class="lang-Java"><span class="hljs-keyword">private</span> MongoClientURI clientURI = <span class="hljs-keyword">new</span> MongoClientURI(<span class="hljs-string">&quot;mongodb://tgor:123456@192.168.x.x:27017,192.168.y.y:27017/testdb?readPreference=secondary&amp;connectTimeoutMS=5000&amp;w=0&quot;</span>);

<span class="hljs-keyword">private</span> MongoClient mongo = <span class="hljs-keyword">new</span> MongoClient(clientURI);

<span class="hljs-meta">@Bean</span>
<span class="hljs-function"><span class="hljs-keyword">protected</span> Datastore <span class="hljs-title">getDatastore</span><span class="hljs-params">()</span> </span>{
    Morphia morphia = <span class="hljs-keyword">new</span> Morphia();
    <span class="hljs-keyword">return</span> morphia.createDatastore(mongo, clientURI.getDatabase());
}
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; tgor.top 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-04-23 15:32:53
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="morphia-API汇总.html" class="navigation navigation-prev " aria-label="Previous page: morphia API汇总">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../Mongodb/mongodb-ObjectId实践.html" class="navigation navigation-next " aria-label="Next page: mongodb ObjectId实践">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"mongodb驱动与连接","level":"1.3.11","depth":2,"next":{"title":"mongodb ObjectId实践","level":"1.3.12","depth":2,"path":"Mongodb/mongodb-ObjectId实践.md","ref":"Mongodb/mongodb-ObjectId实践.md","articles":[]},"previous":{"title":"morphia API汇总","level":"1.3.10","depth":2,"path":"Mongodb-Client/morphia-API汇总.md","ref":"Mongodb-Client/morphia-API汇总.md","articles":[]},"dir":"ltr"},"config":{"plugins":["chapter-fold","splitter","tbfed-pagefooter","page-toc-button","-search","search-pro","popup","back-to-top-button","code","copy-code-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy tgor.top 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"sepia","family":"serif","size":1},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tgor","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"tgor note","gitbook":"*","description":"tgor生活工作记录"},"file":{"path":"Mongodb-Client/mongo驱动连接.md","mtime":"2020-04-23T07:32:53.355Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-29T08:43:24.127Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

